package com.work.demo.entity;

/**
 * @Author: kylin
 * @Date: 2020/10/31 上午11:33
 */
public enum NodeTypeEnum {

    /**
     * 节点类型枚举值
     */

    OWNER, //
    PARTICIPATION, //
    NO_DATA_OWNER, //
    NO_DATA_PARTICIPATION; //

    public static NodeTypeEnum parse(String type) {
        for (NodeTypeEnum value : NodeTypeEnum.values()) {
            if (value.name().equals(type)) {
                return value;
            }
        }
        return null;
    }

    /**
     * 是否是发起方
     *
     * @param type
     * @return
     */
    public static Boolean isOwner(String type) {
        return isOwner(parse(type));
    }

    public static Boolean isOwner(NodeTypeEnum nodeTypeEnum) {
        if (null == nodeTypeEnum) {
            return Boolean.FALSE;
        }
        switch (nodeTypeEnum) {
            case OWNER:
            case NO_DATA_OWNER:
                return Boolean.TRUE;
            case PARTICIPATION:
            case NO_DATA_PARTICIPATION:
                return Boolean.FALSE;
            default:
                return Boolean.FALSE;
        }
    }

    /**
     * 是否无数据方
     *
     * @param nodeTypeEnum
     * @return
     */
    public static Boolean isNoData(NodeTypeEnum nodeTypeEnum) {
        if (null == nodeTypeEnum) {
            return Boolean.FALSE;
        }
        switch (nodeTypeEnum) {
            case NO_DATA_OWNER:
            case NO_DATA_PARTICIPATION:
                return Boolean.TRUE;
            case PARTICIPATION:
            case OWNER:
                return Boolean.FALSE;
            default:
                return Boolean.FALSE;
        }
    }
}
